#!/usr/bin/perl
use strict;
package loft;

require Exporter;
our ($VERSION, @ISA, @EXPORT);

$VERSION = '1.000';
$VERSION = eval $VERSION;

@ISA = qw(Exporter);
@EXPORT = qw($OUT $hdr $IN $LIST rname);

our $dir='split';
our $AUTO='AUTO';
our $hdr=9;
mkdir $dir unless -d $dir;
chdir $dir;
mkdir $AUTO unless -d $AUTO;

our $LIST=$AUTO.'/00_list.txt';
our $OUT='../blob.out';
our $IN='../blob';

my %dirs=qw(
sound mpc|wav
xml xml|xib|bgeom
animate trail|particle|csv|anim
locales fnt|loc
gui png|sprite|pvr|rkm|rk
);
my %autos;
foreach my $d (keys %dirs){map {$autos{$_}=$d} split/\W/,$dirs{$d}}

sub subdir($){my $name=shift;
return $autos{anim} if $name=~/^rk/;
return $autos{$1} if $name=~/\.(\w+)$/;
}

sub rname($)
{my $name=shift;
my @sub=split /\//,$name;
my $sub;
if (@sub==1){
$sub=subdir($name);
@sub=($AUTO,$sub,$name) if $sub;
}

if (@sub>1){my $fp='';$sub=pop @sub;
foreach my $d (@sub){$fp.=$d.'/';mkdir $fp unless -d $fp}
return $fp.$sub}
return $name}

1;